package com.jianan.mis.app.overseastudy;

import static com.jianan.mis.util.ui.calendar.SWTCalendarWrapper.openCalendar;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import com.jianan.mis.app.basedata.ChooseIntermanDialog;
import com.jianan.mis.data.cache.CountryCache;
import com.jianan.mis.data.cache.EmployeeCache;
import com.jianan.mis.data.domain.Country;
import com.jianan.mis.data.domain.Employee;
import com.jianan.mis.data.domain.Interman;
import com.jianan.mis.data.domain.OsContract;
import com.jianan.mis.sys.IGroupKeys;
import com.jianan.mis.sys.IImageKeys;
import com.jianan.mis.sys.IMessageKeys;
import com.jianan.mis.sys.ImageManager;
import com.jianan.mis.sys.ResourceManager;
import com.jianan.mis.sys.SpringBeanFactory;
import com.jianan.mis.util.FtpUtils;
import com.jianan.mis.util.RegularUtils;
import com.jianan.mis.util.StringUtils;

public class OsContractComposite extends Composite {

	private Text txtInterman;
	private Combo comboQuality;
	private Combo comboSchoolCondition;
	private Button btnDownload1;
	private Button btnDownload2;
	private Text txtScan2;
	private Text txtScan1;
	private Combo comboVisaResult;
	private Text txtSendDate;
	private Text txtHandoverDate;
	private Text txtPassport;
	private Text txtCommuTranslateSum;
	private Text txtSum;
	private Text txtContractNo;
	private Combo comboEduLevel;
	private Text txtId;
	private Text txtDate;
	private Combo comboMaterialman;
	private Combo comboConsultant;
	private StyledText txtRemark;
	private Combo comboSource;
	private Text txtOtherSource;
	private Text txtParentsJob;
	private Text txtOtherAsset;
	private Text txtHouse;
	private Text txtStockFund;
	private Text txtSaving;
	private Text txtIntent3;
	private Text txtIntent2;
	private Text txtIntent1;
	private Text txtOtherDirection;
	private Combo comboOsDirection;
	private Combo comboCountryIntent;
	private Text txtMail;
	private Text txtMobilePhone;
	private Text txtPhone;
	private Text txtLangExamGrade1;
	private Combo comboLangExamType1;
	private Text txtLangExamGrade2;
	private Combo comboLangExamType2;
	private Text txtGrade;
	private Text txtGraduateSchool;
	private Text txtGraduateTime;
	private Text txtStartSchoolTime;
	private Text txtSpeciality;
	private Text txtBirthday;
	private Combo comboSex;
	private Text txtName;
	
	final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日");
	final SimpleDateFormat birthdayFormat = new SimpleDateFormat("yyyy年MM月");

	private List<Integer> countryIds = new ArrayList<Integer>();
	private List<Integer> consultantIds = new ArrayList<Integer>();
	private List<Integer> materialmanIds = new ArrayList<Integer>();

	private String[] eduLevels = new String[] {"小学", "初中", "高中", "中专", "大专", "本科", "研究生"};
	private String[] schoolConditions = new String[] {"毕业", "在读"};
	private String[] langExamTypes = new String[] {"TOEFL", "IELTS", "SAT", "GRE", "GAMT", "ACT", "高考"};
	private String[] osDirections = new String[] {"高中", "本科", "研究生", "语言", "交流生", "其它"};
	private String[] sources = new String[] {"报纸广告", "宣传广告", "教育展", "朋友推荐", "其它"};
	private String[] qualities = new String[] {"好", "中", "差"};
	
	private Integer selectedIntermanId = -1;
	
	/**
	 * Create the composite
	 * @param parent
	 * @param style
	 */
	public OsContractComposite(Composite parent, int style) {
		super(parent, style);
		
		final GridLayout gridLayout = new GridLayout();
		gridLayout.marginLeft = 10;
		gridLayout.marginRight = 10;
		gridLayout.numColumns = 6;
		setLayout(gridLayout);

		final Label label = new Label(this, SWT.NONE);
		label.setFont(ResourceManager.getFont("", 16, SWT.BOLD));
		label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 11, 1));
		label.setText("留学签约表");
		
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);

		final Label label_39 = new Label(this, SWT.NONE);
		label_39.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_39.setText("签约日期:");

		txtDate = new Text(this, SWT.BORDER);
		txtDate.setEditable(false);
		txtDate.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				openCalendar(e, txtDate, dateFormat);
			}
		});
		final GridData gd_txtDate = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_txtDate.widthHint = 132;
		txtDate.setLayoutData(gd_txtDate);

		final Label label_40 = new Label(this, SWT.NONE);
		label_40.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_40.setText("签约档案号:");

		txtId = new Text(this, SWT.BORDER);
		txtId.setEnabled(false);
		final GridData gd_txtId = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		txtId.setLayoutData(gd_txtId);
		new Label(this, SWT.NONE);

		final CLabel label_1 = new CLabel(this, SWT.NONE);
		label_1.setFont(ResourceManager.getFont("", 10, SWT.BOLD));
		label_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 6, 1));
		label_1.setText("学生基本信息:");
		label_1.setImage(ImageManager.getImage(IImageKeys.PERSONAL_SETTINGS));

		final Label label_2 = new Label(this, SWT.NONE);
		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_2.setText("学生姓名:");

		txtName = new Text(this, SWT.BORDER);
		txtName.setEditable(false);
		final GridData gd_txtName = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		gd_txtName.widthHint = 80;
		txtName.setLayoutData(gd_txtName);

		final Label label_3 = new Label(this, SWT.NONE);
		label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_3.setText("性别:");

		comboSex = new Combo(this, SWT.READ_ONLY);
		comboSex.setItems(new String[] {"男", "女"});
		final GridData gd_comboSex = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		comboSex.setLayoutData(gd_comboSex);

		final Label label_4 = new Label(this, SWT.NONE);
		label_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_4.setText("出生年月:");

		txtBirthday = new Text(this, SWT.BORDER);
		txtBirthday.setEditable(false);
		txtBirthday.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				openCalendar(e, txtBirthday, birthdayFormat);
			}
		});
		final GridData gd_txtBirthday = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		gd_txtBirthday.widthHint = 79;
		txtBirthday.setLayoutData(gd_txtBirthday);

		final Label label_5 = new Label(this, SWT.NONE);
		label_5.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_5.setText("学历:");

		comboEduLevel = new Combo(this, SWT.READ_ONLY);
		comboEduLevel.setItems(eduLevels);
		final GridData gd_comboEduLevel = new GridData(SWT.FILL, SWT.CENTER, true, false);
		comboEduLevel.setLayoutData(gd_comboEduLevel);
		new Label(this, SWT.NONE);

		final Label label_6 = new Label(this, SWT.NONE);
		label_6.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_6.setText("专业:");

		txtSpeciality = new Text(this, SWT.BORDER);
		final GridData gd_txtSpeciality = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_txtSpeciality.widthHint = 181;
		txtSpeciality.setLayoutData(gd_txtSpeciality);

		final Label label_7 = new Label(this, SWT.NONE);
		label_7.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_7.setText("入读时间:");

		txtStartSchoolTime = new Text(this, SWT.BORDER);
		txtStartSchoolTime.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				openCalendar(e, txtStartSchoolTime, dateFormat);
			}
		});
		txtStartSchoolTime.setEditable(false);
		final GridData gd_txtStartSchoolTime = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_txtStartSchoolTime.widthHint = 110;
		txtStartSchoolTime.setLayoutData(gd_txtStartSchoolTime);

		final Label label_8 = new Label(this, SWT.NONE);
		label_8.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_8.setText("学业状况:");

		comboSchoolCondition = new Combo(this, SWT.NONE);
		comboSchoolCondition.setItems(schoolConditions);
		final GridData gd_comboSchoolCondition = new GridData(SWT.FILL, SWT.CENTER, true, false);
		comboSchoolCondition.setLayoutData(gd_comboSchoolCondition);
		new Label(this, SWT.NONE);

		final Label label_9 = new Label(this, SWT.NONE);
		label_9.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_9.setText("毕业时间:");

		txtGraduateTime = new Text(this, SWT.BORDER);
		txtGraduateTime.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				openCalendar(e, txtGraduateTime, dateFormat);
			}
		});
		txtGraduateTime.setEditable(false);
		final GridData gd_txtGraduateTime = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_txtGraduateTime.widthHint = 110;
		txtGraduateTime.setLayoutData(gd_txtGraduateTime);

		final Label label_10 = new Label(this, SWT.NONE);
		label_10.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_10.setText("毕业院校:");

		txtGraduateSchool = new Text(this, SWT.BORDER);
		final GridData gd_txtGraduateSchool = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_txtGraduateSchool.widthHint = 170;
		txtGraduateSchool.setLayoutData(gd_txtGraduateSchool);

		final Label label_11 = new Label(this, SWT.NONE);
		label_11.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_11.setText("平均成绩:");

		txtGrade = new Text(this, SWT.BORDER);
		final GridData gd_txtGrade = new GridData(SWT.LEFT, SWT.CENTER, true, false, 5, 1);
		gd_txtGrade.widthHint = 99;
		txtGrade.setLayoutData(gd_txtGrade);

		final Label label_12 = new Label(this, SWT.NONE);
		label_12.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_12.setText("语言考试1:");

		comboLangExamType1 = new Combo(this, SWT.READ_ONLY);
		comboLangExamType1.setItems(langExamTypes);
		final GridData gd_comboLangExamType1 = new GridData(SWT.CENTER, SWT.CENTER, true, false);
		comboLangExamType1.setLayoutData(gd_comboLangExamType1);

		txtLangExamGrade1 = new Text(this, SWT.BORDER);
		final GridData gd_txtLangExamGrade1 = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		gd_txtLangExamGrade1.widthHint = 80;
		txtLangExamGrade1.setLayoutData(gd_txtLangExamGrade1);

		final Label label_14 = new Label(this, SWT.NONE);
		label_14.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_14.setText("语言考试2:");

		comboLangExamType2 = new Combo(this, SWT.READ_ONLY);
		comboLangExamType2.setItems(langExamTypes);
		final GridData gd_comboLangExamType2 = new GridData(SWT.CENTER, SWT.CENTER, true, false);
		comboLangExamType2.setLayoutData(gd_comboLangExamType2);

		txtLangExamGrade2 = new Text(this, SWT.BORDER);
		final GridData gd_txtLangExamGrade2 = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		gd_txtLangExamGrade2.widthHint = 80;
		txtLangExamGrade2.setLayoutData(gd_txtLangExamGrade2);

		final Label label_13 = new Label(this, SWT.NONE);
		label_13.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_13.setText("联系电话:");

		txtPhone = new Text(this, SWT.BORDER);
		final GridData gd_txtPhone = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_txtPhone.widthHint = 150;
		txtPhone.setLayoutData(gd_txtPhone);

		final Label label_15 = new Label(this, SWT.NONE);
		label_15.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_15.setText("手机:");

		txtMobilePhone = new Text(this, SWT.BORDER);
		final GridData gd_txtMobilePhone = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_txtMobilePhone.widthHint = 150;
		txtMobilePhone.setLayoutData(gd_txtMobilePhone);

		final Label emailLabel = new Label(this, SWT.NONE);
		emailLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		emailLabel.setText("E-mail:");

		txtMail = new Text(this, SWT.BORDER);
		final GridData gd_txtMail = new GridData(SWT.LEFT, SWT.CENTER, true, false, 5, 1);
		gd_txtMail.widthHint = 239;
		txtMail.setLayoutData(gd_txtMail);

		final CLabel label_17 = new CLabel(this, SWT.NONE);
		label_17.setFont(ResourceManager.getFont("", 10, SWT.BOLD));
		label_17.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 6, 1));
		label_17.setText("留学意向:");
		label_17.setImage(ImageManager.getImage(IImageKeys.INTENT));

		final Label label_18 = new Label(this, SWT.NONE);
		label_18.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_18.setText("主意向国家(必填):");

		comboCountryIntent = new Combo(this, SWT.READ_ONLY);
		final GridData gd_comboCountryIntent = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_comboCountryIntent.widthHint = 90;
		comboCountryIntent.setLayoutData(gd_comboCountryIntent);

		final Label label_22 = new Label(this, SWT.NONE);
		label_22.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_22.setText("留学意向:");

		comboOsDirection = new Combo(this, SWT.READ_ONLY);
		comboOsDirection.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if(comboOsDirection.getSelectionIndex() == 5) {
					txtOtherDirection.setEnabled(true);
				} else {
					txtOtherDirection.setEnabled(false);
					txtOtherDirection.setText("");
				}
			}
		});
		comboOsDirection.setItems(osDirections);
		final GridData gd_comboOsDirection = new GridData(SWT.FILL, SWT.CENTER, true, false);
		comboOsDirection.setLayoutData(gd_comboOsDirection);

		txtOtherDirection = new Text(this, SWT.BORDER);
		txtOtherDirection.setEnabled(false);
		final GridData gd_txtOtherDirection = new GridData(SWT.FILL, SWT.CENTER, true, false);
		txtOtherDirection.setLayoutData(gd_txtOtherDirection);

		final Label label_23 = new Label(this, SWT.NONE);
		label_23.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_23.setText("意向院校及专业:");
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);

		final Label label_24 = new Label(this, SWT.NONE);
		label_24.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_24.setText("1.");

		txtIntent1 = new Text(this, SWT.BORDER);
		final GridData gd_txtIntent1 = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		txtIntent1.setLayoutData(gd_txtIntent1);

		final Label label_25 = new Label(this, SWT.NONE);
		label_25.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_25.setText("2.");

		txtIntent2 = new Text(this, SWT.BORDER);
		final GridData gd_txtIntent2 = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		txtIntent2.setLayoutData(gd_txtIntent2);

		final Label label_26 = new Label(this, SWT.NONE);
		label_26.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_26.setText("3.");

		txtIntent3 = new Text(this, SWT.BORDER);
		final GridData gd_txtIntent3 = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		txtIntent3.setLayoutData(gd_txtIntent3);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);

		final CLabel label_27 = new CLabel(this, SWT.NONE);
		label_27.setFont(ResourceManager.getFont("", 10, SWT.BOLD));
		label_27.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 6, 1));
		label_27.setText("家庭情况:");
		label_27.setImage(ImageManager.getImage(IImageKeys.FAMILY_CONDITION));

		final Label label_28 = new Label(this, SWT.NONE);
		label_28.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_28.setText("1、(存款)");

		txtSaving = new Text(this, SWT.BORDER);
		final GridData gd_txtSaving = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		txtSaving.setLayoutData(gd_txtSaving);

		final Label label_29 = new Label(this, SWT.NONE);
		label_29.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_29.setText("2、(股票基金)");

		txtStockFund = new Text(this, SWT.BORDER);
		final GridData gd_txtStockFund = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		txtStockFund.setLayoutData(gd_txtStockFund);

		final Label label_30 = new Label(this, SWT.NONE);
		label_30.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_30.setText("3、(房产)");

		txtHouse = new Text(this, SWT.BORDER);
		final GridData gd_txtHouse = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		txtHouse.setLayoutData(gd_txtHouse);

		final Label label_31 = new Label(this, SWT.NONE);
		label_31.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_31.setText("3、(其它资产)");

		txtOtherAsset = new Text(this, SWT.BORDER);
		final GridData gd_txtOtherAsset = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		txtOtherAsset.setLayoutData(gd_txtOtherAsset);

		final Label label_32 = new Label(this, SWT.NONE);
		label_32.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_32.setText("父母亲工作:");

		txtParentsJob = new Text(this, SWT.BORDER);
		final GridData gd_txtParentsJob = new GridData(SWT.LEFT, SWT.CENTER, true, false, 5, 1);
		gd_txtParentsJob.widthHint = 440;
		txtParentsJob.setLayoutData(gd_txtParentsJob);

		final CLabel label_38 = new CLabel(this, SWT.NONE);
		label_38.setFont(ResourceManager.getFont("", 10, SWT.BOLD));
		label_38.setText("签约信息:");
		label_38.setImage(ImageManager.getImage(IImageKeys.SIGN));
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);

		final Label label_41 = new Label(this, SWT.NONE);
		label_41.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_41.setText("合同号:");

		txtContractNo = new Text(this, SWT.BORDER);
		txtContractNo.setEditable(false);
		final GridData gd_txtContractNo = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		txtContractNo.setLayoutData(gd_txtContractNo);

		final Label label_55 = new Label(this, SWT.NONE);
		label_55.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_55.setText("通讯翻译费:");

		txtCommuTranslateSum = new Text(this, SWT.BORDER);
		txtCommuTranslateSum.setEditable(false);
		final GridData gd_txtCommuTranslateSum = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_txtCommuTranslateSum.widthHint = 125;
		txtCommuTranslateSum.setLayoutData(gd_txtCommuTranslateSum);

		final Label label_42 = new Label(this, SWT.NONE);
		label_42.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_42.setText("签约金额:");

		txtSum = new Text(this, SWT.BORDER);
		txtSum.setEditable(false);
		final GridData gd_txtSum = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_txtSum.widthHint = 125;
		txtSum.setLayoutData(gd_txtSum);

		final Label label_43 = new Label(this, SWT.NONE);
		label_43.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_43.setText("护照号:");

		txtPassport = new Text(this, SWT.BORDER);
		final GridData gd_txtPassport = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_txtPassport.widthHint = 250;
		txtPassport.setLayoutData(gd_txtPassport);

		final Label label_45 = new Label(this, SWT.NONE);
		label_45.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_45.setText("移交材料部日期:");

		txtHandoverDate = new Text(this, SWT.BORDER);
		txtHandoverDate.setEditable(false);
		final GridData gd_txtHandoverDate = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_txtHandoverDate.widthHint = 110;
		txtHandoverDate.setLayoutData(gd_txtHandoverDate);

		final Label label_46 = new Label(this, SWT.NONE);
		label_46.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_46.setText("材料员:");

		comboMaterialman = new Combo(this, SWT.READ_ONLY);
		comboMaterialman.setEnabled(false);
		final GridData gd_comboMaterialman = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		comboMaterialman.setLayoutData(gd_comboMaterialman);

		final Label label_47 = new Label(this, SWT.NONE);
		label_47.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_47.setText("送签日期:");

		txtSendDate = new Text(this, SWT.BORDER);
		txtSendDate.setEditable(false);
		final GridData gd_txtSendDate = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		gd_txtSendDate.widthHint = 110;
		txtSendDate.setLayoutData(gd_txtSendDate);

		final Label label_48 = new Label(this, SWT.NONE);
		label_48.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_48.setText("签证结果:");

		comboVisaResult = new Combo(this, SWT.READ_ONLY);
		comboVisaResult.setItems(new String[] {"获签", "拒签"});
		final GridData gd_comboVisaResult = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		comboVisaResult.setLayoutData(gd_comboVisaResult);

		final Label label_49 = new Label(this, SWT.NONE);
		label_49.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_49.setText("护照扫描件:");

		txtScan1 = new Text(this, SWT.BORDER);
		final GridData gd_txtScan1 = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
		txtScan1.setLayoutData(gd_txtScan1);

		final Button btnOpen1 = new Button(this, SWT.NONE);
		btnOpen1.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				FileDialog fileDialog = new FileDialog(e.display
						.getActiveShell(), SWT.OPEN);
				String filePath = fileDialog.open();
				if (filePath != null) {
					txtScan1.setText(filePath);
					String fileType = filePath.substring(filePath.lastIndexOf('.'), filePath.length());
					osContract.setScan1(osContract.getContractNo() + "_护照扫描件" + fileType);
					ftpUtils.upload(filePath, osContract.getScan1());
				}
			}
		});
		btnOpen1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		btnOpen1.setText("浏览...");

		btnDownload1 = new Button(this, SWT.NONE);
		btnDownload1.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				FileDialog fileDialog = new FileDialog(e.display
						.getActiveShell(), SWT.SAVE);
				fileDialog.setFileName(osContract.getScan1());
				String filePath = fileDialog.open();
				if (filePath != null) {
					ftpUtils.download(filePath, osContract.getScan1());
				}
			}
		});
		btnDownload1.setText("下载");

		final Label label_50 = new Label(this, SWT.NONE);
		label_50.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_50.setText("签证页扫描件:");

		txtScan2 = new Text(this, SWT.BORDER);
		final GridData gd_txtScan2 = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
		txtScan2.setLayoutData(gd_txtScan2);

		final Button btnOpen2 = new Button(this, SWT.NONE);
		btnOpen2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				FileDialog fileDialog = new FileDialog(e.display
						.getActiveShell(), SWT.OPEN);
				String filePath = fileDialog.open();
				if (filePath != null) {
					txtScan2.setText(filePath);
					String fileType = filePath.substring(filePath.lastIndexOf('.'), filePath.length());
					osContract.setScan2(osContract.getContractNo() + "_签证页扫描件" + fileType);
					ftpUtils.upload(filePath, osContract.getScan2());
				}
			}
		});
		btnOpen2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		btnOpen2.setText("浏览...");

		btnDownload2 = new Button(this, SWT.NONE);
		btnDownload2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				FileDialog fileDialog = new FileDialog(e.display
						.getActiveShell(), SWT.SAVE);
				fileDialog.setFileName(osContract.getScan2());
				String filePath = fileDialog.open();
				if (filePath != null) {
					ftpUtils.download(filePath, osContract.getScan2());
				}
			}
		});
		btnDownload2.setText("下载");

		final CLabel label_33 = new CLabel(this, SWT.NONE);
		label_33.setFont(ResourceManager.getFont("", 10, SWT.BOLD));
		label_33.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 6, 1));
		label_33.setText("其它:");
		label_33.setImage(ImageManager.getImage(IImageKeys.OTHER));

		final Label label_34 = new Label(this, SWT.NONE);
		label_34.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_34.setText("来源:");

		comboSource = new Combo(this, SWT.READ_ONLY);
		comboSource.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if(comboSource.getSelectionIndex() == 4) {
					txtOtherSource.setEnabled(true);
				} else {
					txtOtherSource.setEnabled(false);
					txtOtherSource.setText("");
				}
			}
		});
		comboSource.setItems(sources);
		final GridData gd_comboSource = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		comboSource.setLayoutData(gd_comboSource);

		txtOtherSource = new Text(this, SWT.BORDER);
		txtOtherSource.setEnabled(false);
		final GridData gd_txtOtherSource = new GridData(SWT.FILL, SWT.CENTER, true, false);
		txtOtherSource.setLayoutData(gd_txtOtherSource);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		
		final Label label_35 = new Label(this, SWT.NONE);
		label_35.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
		label_35.setText("备注:");

		txtRemark = new StyledText(this, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER);
		txtRemark.setWordWrap(true);
		final GridData gd_txtRemark = new GridData(SWT.LEFT, SWT.CENTER, true, false, 5, 1);
		gd_txtRemark.heightHint = 50;
		gd_txtRemark.widthHint = 535;
		txtRemark.setLayoutData(gd_txtRemark);

		final Label label_36 = new Label(this, SWT.NONE);
		label_36.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_36.setText("咨询顾问:");

		comboConsultant = new Combo(this, SWT.READ_ONLY);
		comboConsultant.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				/*
				MessageDialog.openInformation(e.display.getActiveShell(),
						IMessageKeys.INFORMATION, "您选择的咨询顾问的员工编号为"
								+ consultantIds.get(comboConsultant.getSelectionIndex()));
				*/
			}
		});
		final GridData gd_comboConsultant = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
		comboConsultant.setLayoutData(gd_comboConsultant);

		final Label label_37 = new Label(this, SWT.NONE);
		label_37.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_37.setText("中间人:");

		txtInterman = new Text(this, SWT.BORDER);
		txtInterman.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				if (e.button == 1) {
					ChooseIntermanDialog dialog = new ChooseIntermanDialog(
							e.display.getActiveShell());
					dialog.open();
					if (dialog.getSelectedInterman() != null) {
						txtInterman.setText(dialog.getSelectedInterman().getName());
						selectedIntermanId = dialog.getSelectedInterman().getId();
					}
				} else {
					txtInterman.setText("");
					selectedIntermanId = -1;
				}
			}
		});
		txtInterman.setEditable(false);
		final GridData gd_txtInterman = new GridData(SWT.FILL, SWT.CENTER, true, false);
		txtInterman.setLayoutData(gd_txtInterman);
		new Label(this, SWT.NONE);
		
		final Label label_51 = new Label(this, SWT.NONE);
		label_51.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_51.setText("客户质量:");

		comboQuality = new Combo(this, SWT.READ_ONLY);
		comboQuality.setItems(qualities);
		final GridData gd_comboQuality = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		comboQuality.setLayoutData(gd_comboQuality);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		
		//
		setupValues();
	}
	
	private int mode = 0;
	
	public void setMode(int mode) {
		this.mode = mode;

		if (mode == 0) {
			// 新增咨询表
			txtDate.setText(dateFormat.format(new Date()));
			txtDate.setEnabled(false);
			comboConsultant.setEnabled(true);
		} else {
			// 修改咨询表
			txtDate.setEnabled(true);
			comboConsultant.setEnabled(false);
		}
	}
	
	private FtpUtils ftpUtils = (FtpUtils) SpringBeanFactory.getBean("ftpUtils");;
	
	private void setupValues() {
		List<Country> countries = CountryCache.getInstance().getAllCountries();
		if (countries != null) {
			for (Country country : countries) {
				countryIds.add(country.getId());
				comboCountryIntent.add(country.getName());
			}
		}
		List<Employee> employees = EmployeeCache.getInstance()
				.getEmployeesByGroups(new String[] { IGroupKeys.OSCONSULTANT, IGroupKeys.OSCHIEF });
		if (employees != null) {
			for (Employee employee : employees) {
				consultantIds.add(employee.getId());
				comboConsultant.add(employee.getName());
			}
		}
		employees = EmployeeCache.getInstance()
				.getEmployeesByGroups(new String[] { IGroupKeys.OSMATERIALMAN, IGroupKeys.OSMATERIALCHIEF });
		if (employees != null) {
			for (Employee employee : employees) {
				materialmanIds.add(employee.getId());
				comboMaterialman.add(employee.getName());
			}
		}
	}
	
	private OsContract osContract;
	
	public void setOsContract(OsContract osContract) {
		this.osContract = osContract;
		
		txtDate.setText(dateFormat.format(osContract.getSignupDate()));
		txtId.setText(osContract.getId().toString());
		// 基本信息
		txtName.setText(osContract.getName());
		if(osContract.isSex()) {
			comboSex.select(0);
		} else {
			comboSex.select(1);
		}
		txtBirthday.setText(birthdayFormat.format(osContract.getBirthday()));
		comboEduLevel.select(ArrayUtils.indexOf(eduLevels, osContract.getEduLevel()));
		if (osContract.getSpeciality() != null)
			txtSpeciality.setText(osContract.getSpeciality());
		else
			txtSpeciality.setText("");
		if (osContract.getStartSchoolTime() != null)
			txtStartSchoolTime.setText(dateFormat.format(osContract.getStartSchoolTime()));
		else
			txtStartSchoolTime.setText("");
		comboSchoolCondition.select(ArrayUtils.indexOf(schoolConditions, osContract.getSchoolCondition()));
		if (osContract.getGraduateTime() != null)
			txtGraduateTime.setText(dateFormat.format(osContract.getGraduateTime()));
		else
			txtGraduateTime.setText("");
		if (osContract.getGraduateSchool() != null)
			txtGraduateSchool.setText(osContract.getGraduateSchool());
		else
			txtGraduateSchool.setText("");
		if (osContract.getGrade() != null)
			txtGrade.setText(osContract.getGrade().toString());
		else
			txtGrade.setText("");
		if(StringUtils.isNotEmpty(osContract.getLangExamType1())) {
			comboLangExamType1.select(ArrayUtils.indexOf(langExamTypes, osContract.getLangExamType1()));
			txtLangExamGrade1.setText(osContract.getLangExamGrade1().toString());
		}
		if(StringUtils.isNotEmpty(osContract.getLangExamType2())) {
			comboLangExamType2.select(ArrayUtils.indexOf(langExamTypes, osContract.getLangExamType2()));
			if (osContract.getLangExamGrade2() != null)
				txtLangExamGrade2.setText(osContract.getLangExamGrade2().toString());
		}
		if (osContract.getPhone() != null)
			txtPhone.setText(osContract.getPhone());
		else
			txtPhone.setText("");
		if (osContract.getMobilePhone() != null)
			txtMobilePhone.setText(osContract.getMobilePhone());
		else
			txtMobilePhone.setText("");
		if (osContract.getMail() != null)
			txtMail.setText(osContract.getMail());
		else
			txtMail.setText("");
		// 留学意向
		comboCountryIntent.select(ArrayUtils.indexOf(countryIds.toArray(), osContract.getCountryIntent().getId()));
		int osDirectionIndex = ArrayUtils.indexOf(osDirections, osContract.getOsDirection());
		if (osDirectionIndex < 0) {
			comboOsDirection.select(osDirections.length - 1);
			txtOtherDirection.setText(osContract.getOsDirection());
			txtOtherDirection.setEnabled(true);
		} else {
			comboOsDirection.select(osDirectionIndex);
		}
		if (osContract.getIntent1() != null)
			txtIntent1.setText(osContract.getIntent1());
		else
			txtIntent1.setText("");
		if (osContract.getIntent2() != null)
			txtIntent2.setText(osContract.getIntent2());
		else
			txtIntent2.setText("");
		if (osContract.getIntent3() != null)
			txtIntent3.setText(osContract.getIntent3());
		else
			txtIntent3.setText("");
		// 家庭情况
		txtSaving.setText(osContract.getSaving());
		txtStockFund.setText(osContract.getStockFund());
		txtHouse.setText(osContract.getHouse());
		txtOtherAsset.setText(osContract.getOtherAsset());
		txtParentsJob.setText(osContract.getParentsJob());
		// 其它
		int sourceIndex = ArrayUtils.indexOf(sources, osContract.getSource());
		if (sourceIndex < 0) {
			comboSource.select(sources.length - 1);
			txtOtherSource.setText(osContract.getSource());
			txtOtherSource.setEnabled(true);
		} else {
			comboSource.select(sourceIndex);
		}
		if (osContract.getRemark() != null) {
			txtRemark.setText(osContract.getRemark());
		}
		comboConsultant.select(ArrayUtils.indexOf(consultantIds.toArray(), osContract.getConsultant().getId()));
		if (osContract.getInterman() != null) {
			txtInterman.setText(osContract.getInterman().getName());
		}
		// 签约信息
		txtContractNo.setText(osContract.getContractNo());
		if (osContract.getCommuTranslateSum() != null) {
			txtCommuTranslateSum.setText(osContract.getCommuTranslateSum().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
		}
		txtSum.setText(osContract.getSignupSum().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
		if (osContract.getPassport() != null) {
			txtPassport.setText(osContract.getPassport());
		}
		if (osContract.getHandoverDate() != null) {
			txtHandoverDate.setText(dateFormat.format(osContract.getHandoverDate()));
		}
		if (osContract.getMaterialman() != null) {
			comboMaterialman.select(ArrayUtils.indexOf(materialmanIds.toArray(), osContract.getMaterialman().getId()));
		}
		if (osContract.getSendDate() != null) {
			txtSendDate.setText(dateFormat.format(osContract.getSendDate()));
		}
		if (osContract.getVisaResult() != null) {
			if (osContract.getVisaResult().equals("获签")) {
				comboVisaResult.select(0);
			} else if (osContract.getVisaResult().equals("拒签")) {
				comboVisaResult.select(1);
			}
		}
		if (osContract.getScan1() != null) {
			txtScan1.setText(osContract.getScan1());
			btnDownload1.setEnabled(true);
		} else {
			btnDownload1.setEnabled(false);
		}
		if (osContract.getScan2() != null) {
			txtScan2.setText(osContract.getScan2());
			btnDownload2.setEnabled(true);
		}
		else {
			btnDownload2.setEnabled(false);
		}
		if(StringUtils.isNotEmpty(osContract.getQuality())) {
			comboQuality.select(ArrayUtils.indexOf(qualities, osContract.getQuality()));
		}
	}

	@SuppressWarnings("unused")
	public boolean checkInfo() {
		if (StringUtils.isEmpty(txtDate.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入签约日期!");
			txtDate.setFocus();
			return false;
		}
		if (StringUtils.isEmpty(txtName.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入姓名!");
			txtName.setFocus();
			return false;
		}
		if (comboSex.getSelectionIndex() < 0) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请选择性别!");
			comboSex.setFocus();
			return false;
		}
		if (StringUtils.isEmpty(txtBirthday.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入出生年月!");
			txtBirthday.setFocus();
			return false;
		}
		if (comboEduLevel.getSelectionIndex() < 0) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请选择学历!");
			comboEduLevel.setFocus();
			return false;
		}
		if (StringUtils.isEmpty(txtStartSchoolTime.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入入读时间!");
			txtStartSchoolTime.setFocus();
			return false;
		}
		if (comboSchoolCondition.getSelectionIndex() < 0) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请选择学业状况!");
			comboSchoolCondition.setFocus();
			return false;
		}
		/*
		if (StringUtils.isEmpty(txtStartSchoolTime.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入入读时间!");
			txtStartSchoolTime.setFocus();
			return false;
		}
		*/
		if (StringUtils.isNotEmpty(txtStartSchoolTime.getText())
				&& StringUtils.isNotEmpty(txtGraduateTime.getText())) {
			try {
				if (!dateFormat.parse(txtGraduateTime.getText()).after(dateFormat.parse(txtStartSchoolTime.getText()))) {
					MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
							"毕业时间必须大于入读时间!");
					txtGraduateTime.setFocus();
					return false;
				}
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		/*
		if (StringUtils.isEmpty(txtGraduateTime.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入毕业时间!");
			txtGraduateTime.setFocus();
			return false;
		}
		if (StringUtils.isEmpty(txtGraduateSchool.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入毕业院校!");
			txtGraduateSchool.setFocus();
			return false;
		}
		if (StringUtils.isEmpty(txtGrade.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入平均成绩!");
			txtGrade.setFocus();
			return false;
		}
		*/
		if (StringUtils.isNotEmpty(txtGrade.getText())) {
			try {
				BigDecimal bd = new BigDecimal(txtGrade.getText());
			} catch(Exception ex) {
				MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
						"平均成绩输入错误,请重新输入!");
				txtGrade.setFocus();
				return false;
			}
			if ((txtGrade.getText().indexOf('.') < 0 && txtGrade.getText().length() > 4
					|| (txtGrade.getText().indexOf('.') >= 0 && txtGrade.getText().substring(0, txtGrade.getText().indexOf('.')).length() > 4))) {
				MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
						"平均成绩不得超过4位,请重新输入!");
				txtGrade.setFocus();
				return false;
			}
			if (txtGrade.getText().indexOf('.') >= 0 
					&& txtGrade.getText().substring(txtGrade.getText().indexOf('.') + 1, txtGrade.getText().length()).length() > 2) {
				MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
						"平均成绩小数点不得超过2位,请重新输入!");
				txtGrade.setFocus();
				return false;
			}
		}
		if (comboLangExamType1.getSelectionIndex() >= 0
				&& StringUtils.isNotEmpty(txtLangExamGrade1.getText())) {
			if (!NumberUtils.isNumber(txtLangExamGrade1.getText())) {
				MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
						"语言考试1成绩输入错误,请重新输入!");
				txtLangExamGrade1.setFocus();
				return false;
			} else if (NumberUtils.toLong(txtLangExamGrade1.getText()) < 0) {
				MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
						"语言考试1成绩必须大于0,请重新输入!");
				txtLangExamGrade1.setFocus();
				return false;
			}
		}
		if (comboLangExamType2.getSelectionIndex() >= 0
				&& StringUtils.isNotEmpty(txtLangExamGrade2.getText())) {
			if (!NumberUtils.isNumber(txtLangExamGrade2.getText())) {
				MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
						"语言考试2成绩输入错误,请重新输入!");
				txtLangExamGrade2.setFocus();
				return false;
			} else if (NumberUtils.toLong(txtLangExamGrade2.getText()) < 0) {
				MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
						"语言考试2成绩必须大于0,请重新输入!");
				txtLangExamGrade2.setFocus();
				return false;
			}
		}
		if (StringUtils.isEmpty(txtPhone.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入联系电话!");
			txtPhone.setFocus();
			return false;
		}
		/*
		if (StringUtils.isEmpty(txtMobilePhone.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入手机!");
			txtMobilePhone.setFocus();
			return false;
		}
		*/
		if (StringUtils.isNotEmpty(txtMobilePhone.getText())
				&& (!NumberUtils.isNumber(txtMobilePhone.getText())
				|| txtMobilePhone.getText().trim().length() != 11)) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"手机输入错误,请重新输入!");
			txtMobilePhone.setFocus();
			return false;
		} 
		/*
		if (StringUtils.isEmpty(txtMail.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入E-mail!");
			txtMail.setFocus();
			return false;
		}
		*/
		if (StringUtils.isNotEmpty(txtMail.getText()) && !RegularUtils.emailCheck(txtMail.getText().trim())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"E-mail格式输入不正确,请重新输入!");
			txtMail.setFocus();
			return false;
		}
		if (comboCountryIntent.getSelectionIndex() < 0) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请选择主意向国家!");
			comboCountryIntent.setFocus();
			return false;
		}
		if (comboOsDirection.getSelectionIndex() < 0) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请选择留学意向!");
			comboOsDirection.setFocus();
			return false;
		}
		if (comboOsDirection.getSelectionIndex() == 5
				&& StringUtils.isEmpty(txtOtherDirection.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入留学意向!");
			txtOtherDirection.setFocus();
			return false;
		}
		/*
		if (StringUtils.isEmpty(txtIntent1.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入意向院校及专业!");
			txtIntent1.setFocus();
			return false;
		}
		*/
		if (StringUtils.isEmpty(txtSaving.getText())
				&& StringUtils.isEmpty(txtStockFund.getText())
				&& StringUtils.isEmpty(txtHouse.getText())
				&& StringUtils.isEmpty(txtOtherAsset.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入家庭资产情况!");
			txtSaving.setFocus();
			return false;
		}
		if (StringUtils.isEmpty(txtParentsJob.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入父母亲工作!");
			txtParentsJob.setFocus();
			return false;
		}
		if (comboSource.getSelectionIndex() < 0) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请选择来源!");
			comboSource.setFocus();
			return false;
		}
		if (comboSource.getSelectionIndex() == 4
				&& StringUtils.isEmpty(txtOtherSource.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入来源!");
			txtOtherSource.setFocus();
			return false;
		}
		/*
		if (comboConsultant.getSelectionIndex() < 0) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请选择咨询顾问!");
			comboConsultant.setFocus();
			return false;
		}
		*/
		if(StringUtils.isNotEmpty(txtCommuTranslateSum.getText())
				&& !NumberUtils.isNumber(txtCommuTranslateSum.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"通讯翻译费输入不正确，请重新输入!");
			txtCommuTranslateSum.setFocus();
			return false;
		}
		if (StringUtils.isEmpty(txtSum.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请输入签约金额!");
			txtSum.setFocus();
			return false;
		}
		if(!NumberUtils.isNumber(txtSum.getText())) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"签约金额输入不正确，请重新输入!");
			txtSum.setFocus();
			return false;
		}
		/*
		if (comboQuality.getSelectionIndex() < 0) {
			MessageDialog.openError(getShell(), IMessageKeys.INFORMATION,
					"请选择客户质量!");
			comboQuality.setFocus();
			return false;
		}
		*/
		
		return true;
	}
	
	public OsContract getOsContract() {
		if(!checkInfo()) return null;
		
		try {
			osContract.setSignupDate(dateFormat.parse(txtDate.getText()));
			osContract.setUpdateDate(new Date());
		} catch (ParseException ex) {
			ex.printStackTrace();
		}
		if(mode != 0) {
			osContract.setId(new Integer(txtId.getText()));
		} else {
		}
		// 基本信息
		osContract.setName(txtName.getText());
		osContract.setSex(comboSex.getSelectionIndex() == 0 ? true : false);
		try {
			osContract.setBirthday(birthdayFormat.parse(txtBirthday.getText()));
		} catch (ParseException ex) {
			ex.printStackTrace();
		}
		osContract.setEduLevel(comboEduLevel.getItem(comboEduLevel.getSelectionIndex()));
		if (StringUtils.isNotEmpty(txtSpeciality.getText()))
			osContract.setSpeciality(txtSpeciality.getText());
		else
			osContract.setSpeciality(null);
		try {
			if (StringUtils.isNotEmpty(txtStartSchoolTime.getText()))
				osContract.setStartSchoolTime(dateFormat.parse(txtStartSchoolTime.getText()));
			else
				osContract.setStartSchoolTime(null);
		} catch (ParseException ex) {
			ex.printStackTrace();
		}
		osContract.setSchoolCondition(comboSchoolCondition.getItem(comboSchoolCondition.getSelectionIndex()));
		try {
			if (StringUtils.isNotEmpty(txtGraduateTime.getText()))
				osContract.setGraduateTime(dateFormat.parse(txtGraduateTime.getText()));
			else
				osContract.setGraduateTime(null);
		} catch (ParseException ex) {
			ex.printStackTrace();
		}
		if (StringUtils.isNotEmpty(txtGraduateSchool.getText()))
			osContract.setGraduateSchool(txtGraduateSchool.getText());
		else
			osContract.setGraduateSchool(txtGraduateSchool.getText());
		if (StringUtils.isNotEmpty(txtGrade.getText()))
			osContract.setGrade(new BigDecimal(txtGrade.getText()));
		else
			osContract.setGrade(null);
		if(comboLangExamType1.getSelectionIndex() >= 0 && StringUtils.isNotEmpty(txtLangExamGrade1.getText())) {
			osContract.setLangExamType1(comboLangExamType1.getItem(comboLangExamType1.getSelectionIndex()));
			osContract.setLangExamGrade1(new BigDecimal(txtLangExamGrade1.getText()));
		}
		if(comboLangExamType2.getSelectionIndex() >= 0 && StringUtils.isNotEmpty(txtLangExamGrade2.getText())) {
			osContract.setLangExamType2(comboLangExamType2.getItem(comboLangExamType2.getSelectionIndex()));
			osContract.setLangExamGrade2(new BigDecimal(txtLangExamGrade2.getText()));
		}
		if (StringUtils.isNotEmpty(txtPhone.getText()))
			osContract.setPhone(txtPhone.getText());
		else
			osContract.setPhone(null);
		if (StringUtils.isNotEmpty(txtMobilePhone.getText()))
			osContract.setMobilePhone(txtMobilePhone.getText());
		else
			osContract.setMobilePhone(null);
		if (StringUtils.isNotEmpty(txtMail.getText()))
			osContract.setMail(txtMail.getText());
		else
			osContract.setMail(null);
		// 留学意向
		osContract.setCountryIntent(new Country(countryIds
				.get(comboCountryIntent.getSelectionIndex())));
		if (comboOsDirection.getSelectionIndex() == 5) {
			osContract.setOsDirection(txtOtherDirection.getText());
		} else {
			osContract.setOsDirection(comboOsDirection.getItem(comboOsDirection.getSelectionIndex()));
		}
		if (StringUtils.isNotEmpty(txtIntent1.getText()))
			osContract.setIntent1(txtIntent1.getText());
		else
			osContract.setIntent1(null);
		if (StringUtils.isNotEmpty(txtIntent2.getText()))
			osContract.setIntent2(txtIntent2.getText());
		else
			osContract.setIntent2(null);
		if (StringUtils.isNotEmpty(txtIntent3.getText()))
			osContract.setIntent3(txtIntent3.getText());
		else
			osContract.setIntent3(null);
		// 家庭情况
		osContract.setSaving(txtSaving.getText());
		osContract.setStockFund(txtStockFund.getText());
		osContract.setHouse(txtHouse.getText());
		osContract.setOtherAsset(txtOtherAsset.getText());
		osContract.setParentsJob(txtParentsJob.getText());
		// 其它
		if (comboSource.getSelectionIndex() == 4) {
			osContract.setSource(txtOtherSource.getText());
		} else {
			osContract.setSource(comboSource.getItem(comboSource
					.getSelectionIndex()));
		}
		osContract.setRemark(txtRemark.getText());
		osContract.setConsultant(new Employee(consultantIds
				.get(comboConsultant.getSelectionIndex())));
		System.out.println(selectedIntermanId);
		if (selectedIntermanId > 0) {
			osContract.setInterman(new Interman(selectedIntermanId));
		} else {
			osContract.setInterman(null);
		}
		// 签约信息
		osContract.setContractNo(txtContractNo.getText());
		if (StringUtils.isNotEmpty(txtCommuTranslateSum.getText()))
			osContract.setCommuTranslateSum(new BigDecimal(txtCommuTranslateSum.getText()));
		else
			osContract.setCommuTranslateSum(null);
		osContract.setSignupSum(new BigDecimal(txtSum.getText()));
		osContract.setPassport(txtPassport.getText());
		try {
			osContract.setHandoverDate(dateFormat.parse(txtHandoverDate.getText()));
		} catch (ParseException ex) {
			ex.printStackTrace();
		}
		if (comboMaterialman.getSelectionIndex() >= 0) {
			osContract.setMaterialman(new Employee(materialmanIds
					.get(comboMaterialman.getSelectionIndex())));
		} else {
			osContract.setMaterialman(null);
		}
		try {
			osContract.setSendDate(dateFormat.parse(txtSendDate.getText()));
		} catch (ParseException ex) {
			ex.printStackTrace();
		}
		if (comboVisaResult.getSelectionIndex() == 0) {
			osContract.setVisaResult("获签");
		} else if (comboVisaResult.getSelectionIndex() == 1) {
			osContract.setVisaResult("拒签");
		}
		/*
		if (StringUtils.isNotEmpty(txtScan1.getText())) {
			osContract.setScan1(txtScan1.getText().trim());
		}
		if (StringUtils.isNotEmpty(txtScan2.getText())) {
			osContract.setScan2(txtScan2.getText().trim());
		}
		*/
		if(comboQuality.getSelectionIndex() >= 0) {
			osContract.setQuality(comboQuality.getItem(comboQuality.getSelectionIndex()));
		}
		
		return osContract;
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}
